﻿using System;

namespace CXW.Core
{
    /// <summary>
    /// Abstract implementation of the <see cref="ICommand"/> interface.
    /// </summary>
    public abstract class AbstractCommand : ICommand
    {
        object owner = null;

        /// <summary>
        /// Returns the owner of the command.
        /// </summary>
        public virtual object Owner
        {
            get { return owner; }
            set
            {
                owner = value;
                OnOwnerChanged(EventArgs.Empty);
            }
        }

        /// <summary>
        /// Invokes the command.
        /// </summary>
        public abstract void Run();

        /// <summary>the owner changed of the command.</summary>
        protected virtual void OnOwnerChanged(EventArgs e)
        {
            if (OwnerChanged != null)
            {
                OwnerChanged(this, e);
            }
        }
        /// <summary>Is called when the Owner property is changed.</summary>
        public event EventHandler OwnerChanged;
    }
}
